{extend name="index-layout" /}
{block name="pagecss"}

<link rel="stylesheet" href="__STATIC__/index/css/style_tr.css">
<link rel="stylesheet" href="__STATIC__/index/css/login.css">
{/block}
{block name="content"}
<div class="banner" style="height:120px;">
    <div class="wrapper">
        <h2 class="wow fadeInUp" style="margin-top:0px;padding-top:20px;">商户登录</h2>
        <p class="wow fadeInUp" data-wow-delay='.5s'>- User login -</p>
    </div>
</div>
<div class="login2">
    <div class="login-wp">
        <div class="login-hd">
            <h2>欢迎登录</h2>
        </div>
        <div class="login-bd">
            <form id="defaultForm" name="defaultForm">
                <div class="account-main c-center">
                    <div>
                        <div class="account-input-cont c-relative">
                            <input id="login-email" type="text" placeholder="邮箱" autocomplete="off" class="account-input">
                            <div class="c-input-checked-icon c-hide login-email-checked" style="display: block;"></div>
                        </div>
                        <div id="email-tip" class="account-tip-cont" style="display: none;">
                            <div class="c-error-icon c-hide" style="display: none;"></div>
                            <div class="c-tip-text">请输入您的邮箱地址</div>
                        </div>
                    </div>
                    <div>
                        <div class="account-input-cont c-relative">
                            <input id="login-password" type="password" placeholder="密码" autocomplete="off" class="account-input">
                            <div class="c-input-checked-icon c-hide login-password-checked"></div>
                        </div>
                        <div class="password-type-con">
                            <div class="password-type-btn"></div>
                            <div class="password-type-btn"></div>
                            <div class="password-type-btn"></div>
                            <div class="password-type-text"></div>
                        </div>
                    </div>
                    <div>
                        <div id="captcha-box" style="margin-top: 20px;margin-bottom: 10px;min-height:44px;"></div>
                        <div id="machine-verify-tip" class="account-tip-cont c-hide">
                            <div class="c-error-icon hide"></div>
                            <div class="c-tip-text c-error-text"></div>
                        </div>
                    </div>
                </div>
            </form>
            <div class="gtpwd">
                <div class="gtpwd-l">
                    <label>
                        <input type="checkbox" class="checkbox1" name="" id="check1" value="" />
                        <label for="check1"></label>记住账户
                    </label>
                </div>
                <div class="gtpwd-r">
                    <a id="btnGetMyPassword" href="javascript:void(0);">忘记密码？</a>
                </div>
            </div>
            <div class="login-btn">
                <input type="button" class="btn account-login-btn account-login-btn-disabled" value="登录" id="embed-submit" />
            </div>
            <!--<div class="login-ft">
                还没有账号？请<a href="/register.html?form=login" >立即注册</a>
            </div>-->
        </div>
    </div>
</div>
{/block}
{block name="pagejs"}
<script src="__INDEX__/js/gt.js"></script>
<script>
    layui.use(['layer'], function (args) {
        var $ = layui.$;
        var layer = layui.layer;
        $('#btnGetMyPassword').click(function () {
            layer.alert('请联系客服!');
        });
    }); 
    $(function() {
        let emailCheck = false;
        let passwordCheck = true;
        let verifyCheck = true;
        let checkboxCheck = true;
        let geetestCheck = false;
        $("#login-email").focus();
        let handler = function(captchaObj) {
            $("#captcha-box").empty();
            captchaObj.appendTo("#captcha-box");
            captchaObj.onSuccess(function() {
                let result = captchaObj.getValidate();
                $.ajax({
                    url: "{:url('index/Login/checkGeetest')}",
                    type: "POST",
                    dataType: "json",
                    data: {
                        geetest_challenge: result.geetest_challenge,
                        geetest_validate: result.geetest_validate,
                        geetest_seccode: result.geetest_seccode
                    }
                }).done(function(data1) {
                    if (data1.status == "success") {
                        geetestCheck = true;
                        $("#tel-cont").show();
                        loginBtnCheck()
                    } else {
                        geetestInit()
                    }
                }).fail(function() {
                    console.log("error")
                })
            });
            window.gt = captchaObj
        };
        let geetestInit = function() {
            $.ajax({
                url: "{:url('index/Login/startGeetest')}",
                type: "get",
                dataType: "json",
            }).done(function(data) {
                let product = "float";
                initGeetest({
                    gt: data.gt,
                    challenge: data.challenge,
                    offline: !data.success,
                    new_captcha: true,
                    product: product,
                    width: "100%"
                }, handler)
            }).fail(function() {
                console.log("error")
            })
        };
        geetestInit();
        $(".c-checkbox").click(function(event) {
            if ($(this).attr("id") == "check") {
                $(this).attr("id", "checked");
                $(this).removeClass("c-checkbox");
                $(this).addClass("c-checkbox-checked");
                $(".account-protocol-tip-cont").hide();
                checkboxCheck = true
            } else {
                $(this).attr("id", "check");
                $(this).removeClass("c-checkbox-checked");
                $(this).addClass("c-checkbox");
                $(".account-protocol-tip-cont").show();
                checkboxCheck = false
            }
            loginBtnCheck()
        });

        function emailFn(email) {
            let tel = $(".account-tel").val();
            email = $.trim(email);
            if (email != "") {
                if (!EmailCheck(email)) {
                    console.log("dfdfdfdf", email);
                    $("#email-tip .c-error-icon").show();
                    $("#email-tip .c-tip-text").addClass("c-error-text");
                    $("#email-tip .c-tip-text").html("请输入正确的邮箱");
                    $(".login-email-checked").hide();
                    $("#login-email").addClass("account-input-error");
                    emailCheck = false;
                    $("#email-tip").show()
                } else {
                    $("#email-tip .c-error-icon").hide();
                    $("#email-tip .c-tip-text").removeClass("c-error-text");
                    $("#email-tip .c-tip-text").html("请输入您的邮箱地址");
                    $(".login-email-checked").show();
                    $("#login-email").removeClass("account-input-error");
                    emailCheck = true;
                    $("#email-tip").hide()
                }
            } else {
                $("#email-tip .c-error-icon").show();
                $("#email-tip .c-tip-text").addClass("c-error-text");
                $(".login-email-checked").hide();
                $("#login-email").addClass("account-input-error");
                emailCheck = false;
                $("#email-tip").show()
            }
            loginBtnCheck()
        }
        $("#login-email").bind("input propertychange", function(event) {
            let email = $(this).val();
            emailFn(email);
            loginBtnCheck()
        });
        $("#login-password").focus(function(event) {
            $("#account-psw-tip").show();
            passwordTip(passwordType($("#login-password").val()));
            let email = $("#login-email").val();
            emailFn(email)
        });

        function loginFn() {
            let email = $.trim($("#login-email").val());
            let password = $("#login-password").val();
            let registerParams = {
                username: email,
                password: password
            };
            let url = window.location.href;
            if (url.indexOf("mtid=") != -1) {
                let mtid = (((url.split("?"))[1]).split("="))[1];
                registerParams.geet_id = mtid
            }
            if (emailCheck && passwordCheck && geetestCheck) {
                console.log("xhr");
                $.post("/login", registerParams, function(data, textStatus, xhr) {
                    console.log("result", data, textStatus, xhr);
                    $("#verify-tip-normal").hide();
                    if (data.code == 1) {
                        debugger;
                        if(data.cashpwd){
                            window.location.href = "/user.html"
                        } else {
                            window.location.href = "{:url(\'index/User/cashpwd\')}"
                        }
                    } else {
                        $("#email-tip .c-error-icon").show();
                        $("#email-tip .c-tip-text").addClass("c-error-text");
                        $("#email-tip .c-tip-text").html(data.msg);
                        $(".login-email-checked").hide();
                        $("#login-email").addClass("account-input-error");
                        emailCheck = false;
                        $("#email-tip").show();
                    }
                })
            }
        }
        $(".account-login-btn").click(function(event) {
            loginFn()
        });

        $(".account-verify-input").bind("input propertychange", function(event) {
            let verifyCode = $(this).val();
            if (verifyCode == "") {
                $(this).addClass("account-input-error");
                verifyCheck = false
            } else {
                $(this).removeClass("account-input-error");
                verifyCheck = true
            }
            loginBtnCheck()
        });
        $(".account-verify-input").keyup(function(event) {
            if (event.keyCode == 13) {
                loginFn()
            }
        });

        function init() {
            let emial = $("#login-email").val();
            let tel = $(".account-tel").val();
            emailFn(emial);
            telephoneFn(tel)
        }

        function EmailCheck(email) {
            let EmailReg = /^[a-zA-Z0-9\-\_\.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/i;
            return EmailReg.test($.trim(email)) && (($.trim(email)).indexOf(" ") == -1)
        }

        function loginBtnCheck() {
            if (emailCheck && passwordCheck && geetestCheck) {
                $(".account-login-btn").removeClass("account-login-btn-disabled")
            } else {
                $(".account-login-btn").addClass("account-login-btn-disabled")
            }
        }

        function passwordType(psw) {
            let reg1 = /^((?![a-z]).)*$/;
            let reg2 = /^((?![A-Z]).)*$/;
            let reg3 = /^((?![0-9]).)*$/;
            if ((!reg1.test(psw) && !reg2.test(psw)) || !reg1.test(psw) && !reg3.test(psw) || !reg2.test(psw) && !reg3.test(psw)) {
                if (!reg1.test(psw) && !reg2.test(psw) && !reg3.test(psw)) {
                    return 3
                } else {
                    return 2
                }
            } else {
                return 1
            }
        }

        function passwordTip(type) {
            if (type != 0) {
                if (type == 1) {
                    $(".password-type-con .password-type-btn:nth-child(1)").css("background", "#FF5B5B");
                    $(".password-type-con .password-type-btn:nth-child(2)").css("background", "#EEE");
                    $(".password-type-con .password-type-btn:nth-child(3)").css("background", "#EEE");
                    $(".password-type-con .password-type-text").css("color", "#CCC");
                    $(".password-type-con .password-type-text").html("弱")
                } else {
                    if (type == 2) {
                        $(".password-type-con .password-type-btn:nth-child(1)").css("background", "#F5A623");
                        $(".password-type-con .password-type-btn:nth-child(2)").css("background", "#F5A623");
                        $(".password-type-con .password-type-btn:nth-child(3)").css("background", "#EEE");
                        $(".password-type-con .password-type-text").css("color", "#CCC");
                        $(".password-type-con .password-type-text").html("中")
                    } else {
                        if (type == 3) {
                            $(".password-type-con .password-type-btn:nth-child(1)").css("background", "#00B374");
                            $(".password-type-con .password-type-btn:nth-child(2)").css("background", "#00B374");
                            $(".password-type-con .password-type-btn:nth-child(3)").css("background", "#00B374");
                            $(".password-type-con .password-type-text").css("color", "#00B374");
                            $(".password-type-con .password-type-text").html("强")
                        }
                    }
                }
                $(".password-type-con").show()
            } else {
                $(".password-type-con").hide()
            }
        }

        function page(title, url, obj, w, h) {
            if(title == null || title == '') {
                title = false;
            };
            if(url == null || url == '') {
                url = "404.html";
            };
            if(w == null || w == '') {
                w = '700px';
            };
            if(h == null || h == '') {
                h = '350px';
            };
            iframeObjName = obj;
            //如果手机端，全屏显示
            if(window.innerWidth <= 768) {
                var index = layer.open({
                    type: 2,
                    title: title,
                    area: [320, h],
                    fixed: false, //不固定
                    content: url
                });
                layer.full(index);
            } else {
                var index = layer.open({
                    type: 2,
                    title: title,
                    area: [w, h],
                    fixed: false, //不固定
                    content: url
                });
            }
        }
    });
</script>
{/block}

